package com.csust.automaticteach.app.agent;

/**
 * @ClassNameReActAgent
 * @Description TODO
 * @Author钰玟
 * @Date2025/6/17 下午10:04
 * @Version 1.0
 **/

import com.csust.automaticteach.exception.BusinessException;
import com.csust.automaticteach.exception.ErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.csust.automaticteach.constant.ExceptionConstant.SYSTEM_ERROR;

/**
 * 思考、执行 的循环模式
 */
@EqualsAndHashCode(callSuper = true)
@Data
public abstract class ReActAgent extends BaseAgent {


    private static final Logger log = LoggerFactory.getLogger(ReActAgent.class);

    public abstract boolean think();

    public abstract String act();


    @Override
    public String step() {
        //思考是否需要调用工具?
        boolean shouldAct = think();
        try {
            if (!shouldAct) {
                //直接返回，无需行动
                return "it's unnecessary to act ";

            }
            return act();
        } catch (Exception e) {
            log.error("error to think or act,the reason is :" + e.getMessage());
//            getMessageList().add(new AssistantMessage(e.getMessage()));
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, SYSTEM_ERROR);
        }
    }
}
